package com.qidian.mespro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mespro.mapper.ProcessStepMapper;
import com.qidian.mespro.service.ProcessStepService;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.ProcessStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description:
 * @ Author: DuYaTao
 * @ Date: 2025/9/18 - 15:15
 */
@Service
public class ProcessStepServiceImpl implements ProcessStepService {

    @Autowired
    private ProcessStepMapper processStepMapper;

    @Override
    public Result<PageInfo<ProcessStep>> getProcessStepByPage(ProcessStep processStep, int pageNum, int size) {
        PageHelper.startPage(pageNum, size);
        List<ProcessStep> pageInfos = processStepMapper.selectList(processStep);
        return Result.success(new PageInfo<>(pageInfos));
    }

    @Override
    public Result<ProcessStep> getProcessStepById(Integer id) {
        return  Result.success(processStepMapper.selectById(id));
    }

    @Override
    public Result<ProcessStep> insert(ProcessStep processStep) {
        return processStepMapper.insert(processStep) == 1 ? Result.success() : Result.error("添加失败");
    }

    @Override
    public Result<ProcessStep> update(ProcessStep processStep) {
        return processStepMapper.update(processStep) == 1  ? Result.success() : Result.error("修改失败");
    }

    @Override
    public Result<ProcessStep> deleteById(Integer id) {
        return processStepMapper.deleteById(id) == 1 ? Result.success() : Result.error("删除失败");
    }
}
